<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
    <script src="./utils/getFeatureGeom.js"></script>
</head>

<body>
    <button onclick="queryByPoint()">点坐标查询</button>
    <div id="map">
    </div>
    <script>
        var docLayer = new Zondy.Map.Doc("", "myTestMap", {

        })
        var map = new ol.Map({
            target: "map",
            layers: [gaode, docLayer],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        // 在一个指定点周围指定半径的区域进行查询：查询地图服务中某个指定图层索引中，
        // 这个圆内所包含的要素。
        function queryByPoint() {
            //创建一个用于查询的点形状
            var pointObj = new Zondy.Object.Point2D(115, 30);// 经纬度
            //设置查询点的搜索半径
            pointObj.nearDis = 3;// 单位？

            /* 1、设置查询结构 */
            //初始化查询结构对象，设置查询结构包含几何信息
            var queryStruct = new Zondy.Service.QueryFeatureStruct();
            //是否包含几何图形信息
            queryStruct.IncludeGeometry = true;
            //是否包含属性信息
            queryStruct.IncludeAttribute = true;
            //是否包含图形显示参数
            queryStruct.IncludeWebGraphic = false;

            /* 2、设置查询规则 */
            var rule = new Zondy.Service.QueryFeatureRule({
                //是否将要素的可见性计算在内
                EnableDisplayCondition: false,
                //是否完全包含
                MustInside: false,
                //是否仅比较要素的外包矩形
                CompareRectOnly: false,
                //是否相交
                Intersect: true
            });
            /* 3、设置查询参数 */
            //实例化查询参数对象
            var queryParam = new Zondy.Service.QueryParameter({
                geometry: pointObj,
                resultFormat: "json",
                struct: queryStruct,
                rule: rule
            });
            /* 4、调用查询服务 */
            //实例化地图文档查询服务对象
            var queryService = new Zondy.Service.QueryDocFeature(queryParam, "myTestMap", 2, {

            });
            //执行查询操作，querySuccess为查询回调函数
            queryService.query(querySuccess);
        }
        const style = new ol.style.Style({
            //形状
            image: new ol.style.Circle({
                radius: 6,
                fill: new ol.style.Fill({
                    color: 'red'
                })
            }),
            stroke: new ol.style.Stroke({
                color: 'green',
                width: 5,
            })
        })
        var source = new ol.source.Vector({

        })
        var layer = new ol.layer.Vector({
            source,
            style,
            opacity: 0.7
        })
        map.addLayer(layer)
        function querySuccess(data) {
            /* mapgis对象 */
            console.log(data, 'data')
            /* ol */
            var format = new Zondy.Format.PolygonJSON();
            //将MapGIS要素JSON反序列化为new ol.Feature({})类型数组Array<new ol.Feature({})>
            var features = format.read(data);
            console.log(features, 'features')// 没查到是null。查到是[e, e, e]。
            if (features) {
                const positions = features.map(item => {
                    return getFeatureGeom(item)
                })
                console.log(positions, 'positions')
                source.addFeatures(features)
            }
        }
    </script>
</body>

</html>